123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
-
-
- namespace app\admin\model;
-
- use think\Db;
- use think\Model;
- use app\admin\logic\ProductLogic;
-
-
- class Product extends Model
- {
-
- protected function initialize()
- {
-
- parent::initialize();
- }
-
-
-
- public function afterSave($aid, $post, $opt, $new = '')
- {
-
- $post['aid'] = $aid;
- $addonFieldExt = !empty($post['addonFieldExt']) ? $post['addonFieldExt'] : array();
- $FieldModel = new \app\admin\model\Field;
- $FieldModel->dealChannelPostData($post['channel'], $post, $addonFieldExt);
-
-
- if (is_dir('./weapp/Waimao/')) {
- $waimaoLogic = new \weapp\Waimao\logic\WaimaoLogic;
- $waimaoLogic->update_htmlfilename($aid, $post, $opt);
- }
-
-
- model('ProductImg')->saveimg($aid, $post);
-
-
-
- $productLogic = new ProductLogic();
- if (empty($new)) {
-
- $productLogic->saveProductAttr($aid, $post['typeid'], $post);
- } else {
-
- $productLogic->saveShopProductAttr($aid, $post['typeid'], $post);
- }
-
-
- model('Taglist')->savetags($aid, $post['typeid'], $post['tags'],$post['arcrank'], $opt);
-
- if ('edit' == $opt) {
-
- Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
- model('SqlCacheTable')->InsertSqlCacheTable(true);
- } else {
-
- if (isset($post['arcrank']) && -1 == $post['arcrank'] && !empty($post['users_id'])) {
-
- model('SqlCacheTable')->UpdateDraftSqlCacheTable($post, $opt);
- } else if (isset($post['arcrank'])) {
-
- $post['old_typeid'] = intval($post['attr']['typeid']);
- model('SqlCacheTable')->UpdateSqlCacheTable($post, $opt, 'product');
- }
- }
- }
-
-
-
- public function getInfo($aid, $field = '', $isshowbody = true)
- {
- $result = array();
- $field = !empty($field) ? $field : '*';
- $result = Db::name('archives')->field($field)
- ->where([
- 'aid' => $aid,
- 'lang' => get_admin_lang(),
- ])
- ->find();
- if ($isshowbody) {
- $tableName = Db::name('channeltype')->where('id','eq',$result['channel'])->getField('table');
- $result['addonFieldExt'] = Db::name($tableName.'_content')->where('aid',$aid)->find();
- }
-
-
- if (!empty($result)) {
- $typeid = isset($result['typeid']) ? $result['typeid'] : 0;
- $tags = model('Taglist')->getListByAid($aid, $typeid);
- $result['tags'] = $tags['tag_arr'];
- $result['tag_id'] = $tags['tid_arr'];
- }
-
- return $result;
- }
-
-
-
- public function afterDel($aidArr = array())
- {
- if (is_string($aidArr)) {
- $aidArr = explode(',', $aidArr);
- }
-
-
- $where = [
- 'aid' => ['IN', $aidArr]
- ];
-
- Db::name('product_content')->where($where)->delete();
-
- Db::name('product_attr')->where($where)->delete();
-
- Db::name('shop_product_attr')->where($where)->delete();
-
- $result = Db::name('product_img')->field('image_url')->where($where)->select();
- if (!empty($result)) {
-
-
-
-
-
-
-
- Db::name('product_img')->where($where)->delete();
- }
-
- Db::name("product_netdisk")->where($where)->delete();
-
- Db::name("product_spec_data")->where($where)->delete();
-
- Db::name("product_spec_value")->where($where)->delete();
-
-
-
- Db::name("product_spec_data_handle")->where($where)->delete();
-
- Db::name("sharp_goods")->where($where)->delete();
-
-
- $where = [
- 'product_id' => ['IN', $aidArr]
- ];
-
- Db::name("shop_order_comment")->where($where)->delete();
-
- Db::name("shop_cart")->where($where)->delete();
-
-
-
-
-
- model('Taglist')->delByAids($aidArr);
-
- del_statistics_data(6, $aidArr);
- }
- }
|