Consult.php 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //竞价单(咨询单)
  10. class Consult extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble =\think\facade\Config::get("noble");
  17. }
  18. public function conlist(){
  19. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  21. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  22. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  23. if ($infoNo !== "") {
  24. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  25. }
  26. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  27. if ($salesman !== "") {
  28. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  29. $where[]= ["b.salesman",'like',"%$salesman%"];
  30. }
  31. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  32. if ($cpName !== "") {
  33. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  34. $where[]= ["a.good_Name",'like',"%$cpName%"];
  35. }
  36. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  37. if ($khNo !== "") {
  38. // $where['khNo'] = $khNo;
  39. $where[]= ["b.khNo",'like',"%$khNo%"];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. // $where['khNo'] = $khNo;
  44. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  45. }
  46. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
  47. if ($relaComNo !== "") $where[]= ['b.companyNo','=',$relaComNo];
  48. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  49. if ($start !="") {
  50. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  51. $where[]= ["a.addtime",'>=',$start];
  52. }
  53. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  54. if($end !=""){
  55. $where[]= ["a.addtime",'<=',$end];
  56. }
  57. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  58. if ($status !== "") {
  59. $where[]= ["a.status",'=',$status];
  60. }
  61. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  62. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  63. // $role=$this->checkRole();
  64. // if(!empty($role['write'])){
  65. // $where[]=["b.createrid","in",$role['write']];
  66. // }
  67. // $role = $this->checkDataShare();
  68. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
  69. $role = $this->checkDataShare();
  70. $hand = resign_hand_user($this->uid,0);
  71. if (!empty($role[DataGroupModel::$type_全部])) {
  72. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  73. $where[] = ['b.createrid', 'in',$arr];
  74. }
  75. // if(!empty($role['platform']) ){
  76. // $where[]=["b.platform_code","in",$role['platform']];
  77. // }
  78. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->count();
  79. $total = ceil($count / $size);
  80. $page = $page >= $total ? $total : $page;
  81. $list = Db::name('consult_info')
  82. ->alias("a")
  83. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  84. ->where($where)
  85. ->page($page, $size)
  86. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")
  87. ->order("a.id desc")
  88. ->select()
  89. ->toArray();
  90. $all_createrid = array_column($list,'createrid');
  91. $item = get_company_name_by_uid($all_createrid);
  92. $data=[];
  93. foreach ($list as $value){
  94. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  95. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'], true):[];
  96. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  97. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  98. $value['khname']="";
  99. if($value['khNo']!==""){
  100. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  101. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  102. }
  103. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  104. $value['company_name'] = $item[$value['createrid']]??'';
  105. //是否具有编辑权限
  106. $value['is_allow_update'] = 0;
  107. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  108. $data[]=$value;
  109. }
  110. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  111. }
  112. public function info(){
  113. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  114. if($id==""){
  115. return error_show(1002,"咨询单编号不能为空");
  116. }
  117. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  118. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  119. $fo['can']=$in;
  120. if(empty($fo)){
  121. return error_show(1002,"未找到咨询单编号");
  122. }else{
  123. return app_show(0,"获取成功",$fo);
  124. }
  125. }
  126. public function del(){
  127. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  128. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  129. if($de==false){
  130. return error_show(1002,'咨询单信息未找到');
  131. }
  132. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  133. if($dell){
  134. return error_show(0,"删除成功");
  135. }else
  136. return error_show(1002,"删除失败");
  137. }
  138. public function create(){
  139. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  140. if($is_project===""){
  141. return error_show(1002,"参数is_project不能为空");
  142. }
  143. if($is_project==1){
  144. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  145. if($projectNo===""){
  146. return error_show(1002,"参数projectNo不能为空");
  147. }
  148. }
  149. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  150. if($khNo===""){
  151. return error_show(1002,"参数khNo不能为空");
  152. }
  153. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  154. if($companyNo===""){
  155. return error_show(1002,"参数companyNo不能为空");
  156. }
  157. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  158. if($endtime===""){
  159. return error_show(1002,"参数endtime不能为空");
  160. }
  161. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  162. "";
  163. if($platform_code===""){
  164. return error_show(1002,"参数platform_code不能为空");
  165. }
  166. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  167. if($ladder==""){
  168. return error_show(1005,"参数ladder不能为空");
  169. }
  170. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  171. if($token==''){
  172. return error_show(105,"参数token不能为空");
  173. }
  174. $user =GetUserInfo($token);
  175. if(empty($user)||$user['code']!=0){
  176. return error_show(102,"用户数据不存在");
  177. }
  178. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  179. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  180. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  181. $zxNo=makeNo("ZX");
  182. Db::startTrans();
  183. try{
  184. $data=[
  185. "zxNo"=>$zxNo,
  186. "createrid"=>$createrid,
  187. "creater"=>$creater,
  188. "is_project"=>$is_project,
  189. "projectNo"=>isset($projectNo) ? $projectNo:"",
  190. "khNo"=>$khNo,
  191. "companyNo"=>$companyNo,
  192. "endtime"=>$endtime,
  193. "salesman"=>$creater,
  194. "platform_code"=>$platform_code,
  195. "saleid"=>$createrid,
  196. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  197. "status"=>0,
  198. "is_del"=>0,
  199. "addtime"=>date("Y-m-d H:i:s"),
  200. "updatetime"=>date("Y-m-d H:i:s"),
  201. ];
  202. $zx = Db::name("consult_order")->insert($data);
  203. if($zx){
  204. //判断是否是项目,且该项目是否存在台账记录中
  205. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  206. foreach ($ladder as $value){
  207. $infoNo=makeNo("IF");
  208. $specinfo=[];
  209. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  210. foreach ($value["specinfo"] as $v){
  211. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  212. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  213. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  214. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  215. $specinfo[]=$v;
  216. }
  217. }
  218. $info=[
  219. "infoNo"=>$infoNo,
  220. "zxNo"=>$zxNo,
  221. "spuCode"=>"",
  222. "good_name"=>$value['good_name'],
  223. "good_img"=>$value['good_img'],
  224. "cat_id"=>$value['cat_id'],
  225. "unit"=>$value['unit'],
  226. "brand_id"=>$value['brand_id'],
  227. "arrival_time"=>$value['arrival_time'],
  228. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  229. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  230. "is_addrs"=>$value['is_addrs'],
  231. "is_custom"=>$value['is_custom'],
  232. "metal_id"=>$value['metal_id'],
  233. "config"=>isset($value['config'])?$value['config']:"",
  234. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  235. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  236. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  237. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  238. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  239. "budget_price"=>$value['budget_price'],
  240. "num"=>$value['num'],
  241. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  242. "use_desc"=>$value['use_desc'],
  243. "remark"=>$value['remark'],
  244. "status"=>1,
  245. "is_del"=>0,
  246. "addtime"=>date("Y-m-d H:i:s"),
  247. "updatetime"=>date("Y-m-d H:i:s"),
  248. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  249. ];
  250. $up = Db::name("consult_info")->insertGetId($info);
  251. if(!$up){
  252. Db::rollback();
  253. return error_show(1004,'添加失败');
  254. }else{
  255. //修改状态
  256. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  257. "order_code" => $infoNo,//咨询单详情编号
  258. "status" => 1,//这里的status是之前的值
  259. "action_remark" => '',//备注
  260. "action_type" => "create"//新建create,编辑edit,更改状态status
  261. ], "ZXD", 1, $info);
  262. //竞价单不走流程,不推待办已办
  263. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  264. // "order_type" => 'ZXD',
  265. // "order_code" => $infoNo,//咨询单详情编号
  266. // "order_id" => $up,
  267. // "order_status" => 1,
  268. // 'before_status'=>0
  269. // ]);
  270. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  271. if (isset($stand_exists)) {
  272. Db::name('standing_book')
  273. ->where('id', $stand_exists['id'])
  274. ->update([
  275. 'infoNo' => $infoNo,
  276. 'updatetime' => date('Y-m-d H:i:s')
  277. ]);
  278. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  279. } else {
  280. //添加台账信息
  281. Db::name('standing_book')
  282. ->insert([
  283. 'standBookNo' => makeNo("IO"),
  284. 'projectNo' => isset($projectNo) ? $projectNo : '',
  285. 'infoNo' => $infoNo,
  286. 'companyNo' => $companyNo,
  287. 'customer_code' => $khNo,
  288. 'addtime' => date('Y-m-d H:i:s'),
  289. 'updatetime' => date('Y-m-d H:i:s')
  290. ]);
  291. }
  292. }
  293. }
  294. Db::commit();
  295. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  296. }else{
  297. Db::rollback();
  298. return error_show(1004,"新建失败");
  299. }
  300. }catch (\Exception $e){
  301. Db::rollback();
  302. return error_show(1003,$e->getMessage());
  303. }
  304. }
  305. public function zxinfo(){
  306. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  307. if($infoNo==""){
  308. return error_show(1004,"参数infoNo不能为空");
  309. }
  310. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  311. if($zxinfo==false){
  312. return error_show(1004,"未找到信息数据");
  313. }
  314. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  315. if($zxorder==false){
  316. return error_show(1004,"未找到咨询信息数据");
  317. }
  318. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  319. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  320. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  321. $zxinfo['khname']="";
  322. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  323. $zxinfo['khNo']="";
  324. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  325. $zxinfo['brand']="";
  326. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  327. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  328. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  329. $zxinfo['company']="";
  330. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  331. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  332. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  333. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  334. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  335. $zxinfo['project_name']="";
  336. $zxinfo['budget_total']="";
  337. $zxinfo['departinfo']=[];
  338. $zxinfo['unit_name']="";
  339. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  340. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  341. if($zxorder['khNo']!==""){
  342. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  343. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  344. $zxinfo['khNo']= $zxorder['khNo'];
  345. }
  346. if($zxinfo['unit']!==""){
  347. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  348. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  349. }
  350. if($zxinfo['brand_id']!==""){
  351. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  352. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  353. }
  354. if($zxorder['companyNo']!==""){
  355. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  356. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  357. }
  358. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  359. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  360. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  361. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  362. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  363. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  364. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  365. }
  366. if($zxorder['depart']>0){
  367. $userCommon = new \app\admin\common\User();
  368. $tmp = $userCommon->handle('ciinfo',['id'=>$zxorder['depart']]);
  369. $zxinfo['departinfo']=$tmp['data'];
  370. }
  371. if($zxorder['platform_code']>0){
  372. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  373. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  374. }
  375. return app_show(0,"获取成功",$zxinfo);
  376. }
  377. public function zxedit(){
  378. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  379. if($infoNo==""){
  380. return error_show(1004,"参数infoNo不能为空");
  381. }
  382. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  383. if($zxinfo==false){
  384. return error_show(1004,"未找到信息数据");
  385. }
  386. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  387. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  388. if($good_name==""){
  389. return error_show(1003,"参数good_name不能为空");
  390. }
  391. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  392. if($good_img==""){
  393. return error_show(1003,"参数good_img不能为空");
  394. }
  395. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  396. if($cat_id==""){
  397. return error_show(1003,"参数cat_id不能为空");
  398. }
  399. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  400. if($unit==""){
  401. return error_show(1003,"参数unit不能为空");
  402. }
  403. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  404. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  405. if($arrival_time==""){
  406. return error_show(1003,"参数arrival_time不能为空");
  407. }
  408. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  409. if($specin==""){
  410. return error_show(1003,"参数specinfo不能为空");
  411. }
  412. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  413. // if($cost_desc==""){
  414. // return error_show(1003,"参数cost_desc不能为空");
  415. // }
  416. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  417. if($is_addrs===""){
  418. return error_show(1003,"参数is_addrs不能为空");
  419. }
  420. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  421. if($is_custom===""){
  422. return error_show(1003,"参数is_custom不能为空");
  423. }
  424. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  425. if($metal_id===""){
  426. return error_show(1003,"参数metal_id不能为空");
  427. }
  428. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  429. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  430. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  431. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  432. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  433. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  434. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  435. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  436. if($num===""){
  437. return error_show(1003,"参数num不能为空");
  438. }
  439. if($budget_price===""){
  440. return error_show(1003,"参数budget_price不能为空");
  441. }
  442. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  443. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  444. if($use_desc==""){
  445. return error_show(1003,"参数use_desc不能为空");
  446. }
  447. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  448. if($remark==""){
  449. return error_show(1003,"参数remark不能为空");
  450. }
  451. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  452. if($endtime==""){
  453. return error_show(1003,"参数endtime不能为空");
  454. }
  455. if($metal_id!=0){
  456. if($config==""){
  457. return error_show(1003,"参数config不能为空");
  458. }
  459. if($other_config==""){
  460. return error_show(1003,"参数other_config不能为空");
  461. }
  462. if($specs_weight===""){
  463. return error_show(1003,"参数specs_weight不能为空");
  464. }
  465. if($gold_price===""){
  466. return error_show(1003,"参数gold_price不能为空");
  467. }
  468. }
  469. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  470. if($token==''){
  471. return error_show(102,"参数token不能为空");
  472. }
  473. $user =GetUserInfo($token);
  474. if(empty($user)||$user['code']!=0){
  475. return error_show(105,"用户数据不存在");
  476. }
  477. $specinfo=[];
  478. foreach ($specin as $v){
  479. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  480. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  481. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  482. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  483. $specinfo[]=$v;
  484. }
  485. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  486. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  487. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  488. Db::startTrans();
  489. try{
  490. $innew =makeNo("IF");
  491. $info=[
  492. "infoNo"=>$innew,
  493. "zxNo"=>$zxinfo['zxNo'],
  494. "spuCode"=>"",
  495. "good_name"=>$good_name,
  496. "good_img"=>$good_img,
  497. "cat_id"=>$cat_id,
  498. "unit"=>$unit,
  499. "brand_id"=>$brand_id,
  500. "arrival_time"=>$arrival_time,
  501. "specinfo"=>json_encode($specinfo),
  502. // "color"=>$color,
  503. // "material"=>$material,
  504. "cost_desc"=>$cost_desc,
  505. "is_addrs"=>$is_addrs,
  506. "is_custom"=>$is_custom,
  507. "metal_id"=>$metal_id,
  508. "config"=>$config,
  509. "other_config"=>$other_config,
  510. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  511. "gold_price"=>$gold_price===""? 0 : $gold_price,
  512. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  513. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  514. "budget_price"=>$budget_price,
  515. "num"=>$num,
  516. "pgNo"=>$pgNo,
  517. "use_desc"=>$use_desc,
  518. "remark"=>$remark,
  519. "bargain_num"=>$zxinfo['bargain_num']+1,
  520. "status"=>1,
  521. "is_del"=>0,
  522. "addtime"=>date("Y-m-d H:i:s"),
  523. "updatetime"=>date("Y-m-d H:i:s"),
  524. 'bargain_status'=>1,
  525. 'enclosure_file'=>$enclosure_file
  526. ];
  527. $up = Db::name("consult_info")->insert($info);
  528. if($up){
  529. //操作记录
  530. ActionLog::logAdd($this->post['token'], [
  531. "order_code" => $innew,//咨询单详情编号
  532. "status" => 1,//这里的status是之前的值
  533. "action_remark" => '',//备注
  534. "action_type" => "edit"//新建create,编辑edit,更改状态status
  535. ], "ZXD", 1, $this->post);
  536. // ProcessOrder::AddProcess($this->post['token'], [
  537. // "order_type" => 'ZXD',
  538. // "order_code" => $innew,//咨询单详情编号
  539. // "order_id" => 0,
  540. // "order_status" => 1
  541. // ]);
  542. if (!empty($bidlist)){
  543. foreach ($bidlist as $value){
  544. unset($value['id']);
  545. $value['infoNo']=$innew;
  546. $value['bidNo']=makeNo("BD");
  547. $value['spuCode']=makeNo("SKU");
  548. $value['status'] =0;
  549. $value['updatetime'] =date("Y-m-d H:i:s");
  550. $in = Db::name("consult_bids")->insert($value);
  551. if($in==false){
  552. Db::rollback();
  553. return error_show(1004,"反馈商品新建失败");
  554. }
  555. ActionLog::logAdd($this->post['token'], [
  556. "order_code" => $innew,//咨询单详情编号
  557. "status" => 1,//这里的status是之前的值
  558. "action_remark" => '',//备注
  559. "action_type" => "edit"//新建create,编辑edit,更改状态status
  560. ], "FKD", 1, $this->post);
  561. }
  562. }
  563. $zxinfo["bargain_status"] =1;
  564. $zxinfo["status"] =6;
  565. $zxinfo["bargain_code"] =$innew;
  566. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  567. $bar=Db::name("consult_info")->save($zxinfo);
  568. if($bar==false){
  569. Db::rollback();
  570. return error_show(1004,"反馈商品更新失败");
  571. }else{
  572. //修改状态,添加待办
  573. ActionLog::logAdd($this->post['token'], [
  574. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  575. "status" => $zxinfo['status'],//这里的status是之前的值
  576. "action_remark" => '',//备注
  577. "action_type" => "edit"//新建create,编辑edit,更改状态status
  578. ], "ZXD", $zxinfo['status'], $zxinfo);
  579. }
  580. //更新consule_order记录
  581. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  582. 'updatetime'=>date('Y-m-d H:i:s')]);
  583. if($op==false){
  584. Db::rollback();
  585. return error_show(1004,'咨询单结束时间更新失败');
  586. }
  587. //维护台账记录
  588. $insert_standing_book_data=[
  589. 'standBookNo'=>makeNo('IO'),
  590. 'infoNo'=>$innew,
  591. 'addtime' => date('Y-m-d H:i:s'),
  592. 'updatetime' => date('Y-m-d H:i:s')
  593. ];
  594. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  595. if(!empty($temp_project)){
  596. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  597. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  598. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  599. }
  600. Db::name('standing_book')->insert($insert_standing_book_data);
  601. Db::commit();
  602. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  603. }
  604. }catch (\Exception $e){
  605. Db::rollback();
  606. return error_show(1004,$e->getMessage());
  607. }
  608. }
  609. //** 发布竞标任务 */
  610. public function bargain(){
  611. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  612. if($infoNo==""){
  613. return error_show(1004,"参数infoNo不能为空");
  614. }
  615. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  616. if($zxinfo==false){
  617. return error_show(1004,"未找到信息数据");
  618. }
  619. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  620. if($status===""){
  621. return error_show(1004,"参数status不能为空");
  622. }
  623. // if($status==1&&$zxinfo['status']>1){
  624. // $zxinfo['bargain_num']=+1;
  625. // }
  626. $old_zxinfo_status = $zxinfo['status'];
  627. $zxinfo['status']=$status;
  628. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  629. $up = Db::name("consult_info")->save($zxinfo);
  630. if($up){
  631. //修改状态,添加待办
  632. ActionLog::logAdd($this->post['token'], [
  633. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  634. "status" => $old_zxinfo_status,//这里的status是之前的值
  635. "action_remark" => '',//备注
  636. "action_type" => "status"//新建create,编辑edit,更改状态status
  637. ], "ZXD", $zxinfo['status'], $zxinfo);
  638. return app_show(0,"状态更新成功");
  639. }else{
  640. return error_show(1003,"状态更新失败");
  641. }
  642. }
  643. //反馈商品添加
  644. public function feadback(){
  645. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  646. if($infoNo==""){
  647. return error_show(1002,"参数infoNo不能为空");
  648. }
  649. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  650. if($zxinfo==false){
  651. return error_show(1003,"未找到信息数据");
  652. }
  653. if($zxinfo['status']!=1){
  654. return error_show(1004,"任务未进行");
  655. }
  656. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  657. if($zx==false){
  658. return error_show(1003,"未找咨询信息数据");
  659. }
  660. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  661. if($pname==""){
  662. return error_show(1002,"参数pname不能为空");
  663. }
  664. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  665. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  666. if($cat_id==""){
  667. return error_show(1002,"参数cat_id不能为空");
  668. }
  669. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  670. if($specin==""){
  671. return error_show(1003,"参数specinfo不能为空");
  672. }
  673. $specinfo=[];
  674. foreach ($specin as $v){
  675. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  676. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  677. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  678. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  679. $specinfo[]=$v;
  680. }
  681. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  682. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  683. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  684. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  685. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  686. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
  687. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  688. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  689. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  690. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  691. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  692. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  693. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  694. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  695. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  696. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  697. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  698. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  699. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  700. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  701. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  702. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  703. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  704. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  705. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  706. if($nake_fee==="" ){
  707. return error_show(1004,"参数nake_fee不能为空");
  708. }
  709. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  710. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  711. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  712. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  713. if($delivery_place==''){
  714. return error_show(1002,"参数delivery_place不能为空");
  715. }
  716. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  717. if($token==''){
  718. return error_show(1002,"参数token不能为空");
  719. }
  720. $user =GetUserInfo($token);
  721. if(empty($user)||$user['code']!=0){
  722. return error_show(1005,"用户数据不存在");
  723. }
  724. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  725. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  726. $bidNo=makeNo("BD");
  727. $spucode=makeNo("SKU");
  728. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  729. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  730. //部分参数的大小校验
  731. $vali = Validate::rule([
  732. 'expire_day|有效时长'=>'require|elt:214748364',
  733. 'delivery_day|物流时长'=>'require|elt:214748364',
  734. 'work_day|生产工期'=>'require|elt:214748364',
  735. 'weight|总重量'=>'require|max:10',
  736. ]);
  737. $temp = [
  738. 'expire_day'=>$expire_day,
  739. 'delivery_day'=>$delivery_day,
  740. 'work_day'=>$work_day,
  741. 'weight'=>$weight,
  742. ];
  743. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  744. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  745. $cat_top_list = made($cat_id);
  746. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  747. if ($is_gold_price == 1 && $cat_top_id == 6) {
  748. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  749. ->find();
  750. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  751. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  752. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  753. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  754. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  755. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  756. $saleprice = $total_fee/ (1 - $budget);
  757. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  758. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  759. }else{
  760. if($nake_fee){
  761. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  762. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  763. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  764. }else{
  765. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  766. (1 - $budget);
  767. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  768. }
  769. }
  770. $supplier = Db::name('supplier')
  771. ->field('id,person,personid')
  772. ->where('code',$supplierNo)
  773. ->findOrEmpty();
  774. $data=[
  775. "bidNo"=>$bidNo,
  776. "infoNo"=>$infoNo,
  777. "zxNo"=>$zxinfo['zxNo'],
  778. "spuCode"=>$spucode,
  779. "good_name"=>$pname,
  780. "brand_id"=>$brandid,
  781. "cat_id"=>$cat_id,
  782. "specinfo"=>json_encode($specinfo),
  783. "unit_id"=>$unit_id,
  784. "cost_desc"=>$cost_desc,
  785. "work_day"=>$work_day,
  786. "delivery_day"=>$delivery_day,
  787. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  788. "expire_day"=>$expire_day,
  789. "origin_place"=>$origin_place,
  790. "supplierNo"=>$supplierNo,
  791. "pay_way"=>$pay_way,
  792. "tax"=>$tax,
  793. "send_way"=>$send_way,
  794. "metal_id"=>$metal_id,
  795. "is_gold_price"=>$is_gold_price,
  796. "config"=>$config,
  797. "other_config"=>$other_config,
  798. "weight"=>$weight,
  799. "good_weight"=>$good_weight,
  800. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  801. "is_diff"=>$is_diff,
  802. "demo_fee"=>$demo_fee,
  803. "delivery_fee"=>$delivery_fee,
  804. "open_fee"=>$open_fee,
  805. "pakge_fee"=>$pakge_fee,
  806. "nake_fee"=>$nake_fee,
  807. "mark_fee"=>$mark_fee,
  808. "cert_fee"=>$cert_fee,
  809. "cost_fee"=>$cost_fee,
  810. "total_fee"=>$total_fee,
  811. "supply_area"=>$supply_area,
  812. "remark"=>$remark,
  813. "sale_price"=>$saleprice,
  814. "sale_cost_fee"=>$sale_cost_fee,
  815. "origin_cost_fee"=>$sale_cost_fee,
  816. "origin_price"=>$saleprice,
  817. "createrid"=>$createrid,
  818. "creater"=>$creater,
  819. "status"=>$zxinfo['status']==1 ?1 :2,
  820. "is_del"=>0,
  821. "addtime"=>date("Y-m-d H:i:s"),
  822. "updatetime"=>date("Y-m-d H:i:s"),
  823. 'delivery_place'=>$delivery_place,//发货地
  824. 'cgder' => $supplier['person'] ?? '',
  825. 'cgderid' => $supplier['personid'] ?? 0,
  826. ];
  827. Db::startTrans();
  828. try{
  829. $insert= Db::name("consult_bids")->insert($data);
  830. if($insert){
  831. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  832. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  833. if($projectinfo==false){
  834. Db::rollback();
  835. return error_show(1006,"未找到项目信息");
  836. }
  837. $temp=[];
  838. $temp['spuCode']=$spucode;
  839. $temp['skuCode']="";
  840. $temp['pgNo']=$zxinfo['pgNo'];
  841. $temp['projectNo']=$zx['projectNo'];
  842. $temp['good_name']=$pname;
  843. $temp['good_type']=$projectinfo['good_type'];
  844. $temp['data_source']=2;
  845. $temp['cat_id']=$cat_id;
  846. $temp['budget_price']=$projectinfo['budget_price'];
  847. $temp['sale_price']=$saleprice;
  848. $temp['origin_price']=$total_fee;
  849. $temp['num']=$zxinfo['num'];
  850. $temp['status']=0;
  851. $temp['is_del']=0;
  852. $temp['creater']=$creater;
  853. $temp['createrid']=$createrid;
  854. $temp['addtime']=date("Y-m-d H:i:s");
  855. $temp['updatetime']=date("Y-m-d H:i:s");
  856. $nu = Db::name("project_feedback")->insert($temp);
  857. if($nu==false){
  858. Db::rollback();
  859. return error_show(1006,"项目反馈失败");
  860. }else{
  861. $old_projectinfo_status = $projectinfo['status'];
  862. $projectinfo['status']=2;
  863. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  864. $up = Db::name("project_info")->save($projectinfo);
  865. if($up){
  866. //修改状态,添加待办,只记录动作
  867. ActionLog::logAdd($this->post['token'], [
  868. "order_code" => $projectinfo['pgNo'],//编码
  869. "status" => $old_projectinfo_status,//这里的status是之前的值
  870. "action_remark" => '',//备注
  871. "action_type" => "status"//新建create,编辑edit,更改状态status
  872. ], "PRI", 2, $projectinfo);
  873. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  874. ->count();
  875. if($count==0){
  876. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  877. if($projetc!=false){
  878. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  879. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  880. if($proc==false){
  881. Db::rollback();
  882. return error_show(1006,"项目反馈失败");
  883. }else{
  884. //修改状态,添加待办
  885. ActionLog::logAdd($this->post['token'], [
  886. "order_code" => $projetc['projectNo'],//项目编码
  887. "status" => 1,//这里的status是之前的值
  888. "action_remark" => '',//备注
  889. "action_type" => "status"//新建create,编辑edit,更改状态status
  890. ], "PRO", 2, $projetc);
  891. ProcessOrder::AddProcess($this->post['token'], [
  892. "order_type" => 'PRO',
  893. "order_code" => $projetc['projectNo'],
  894. "order_id" => $projetc['id'],
  895. "order_status" => 2,"before_status"=>1
  896. ]);
  897. }
  898. }
  899. }
  900. }
  901. }
  902. }
  903. Db::commit();
  904. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  905. }else{
  906. Db::rollback();
  907. return error_show(1006,"反馈失败");
  908. }
  909. }catch (\Exception $e){
  910. Db::rollback();
  911. return error_show(1006,$e->getMessage());
  912. }
  913. }
  914. //反馈商品详情
  915. public function feadinfo(){
  916. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  917. if($bidNo==""){
  918. return error_show(1004,"参数bidNo不能为空");
  919. }
  920. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  921. if($info==false){
  922. return error_show(1004,"未找到商品数据");
  923. }
  924. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  925. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  926. $info['cat_info'] = made($info['cat_id'],[]);
  927. $info['noble_weight'] = $info['good_weight'];
  928. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  929. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  930. if($info['brand_id']!=0){
  931. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  932. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  933. }else{
  934. $info["brand_name"]="";
  935. $info["brand_id"]="";
  936. }
  937. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  938. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  939. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  940. $god=[
  941. "metal_id"=>$info['metal_id'],
  942. "weight"=>$info["good_weight"],
  943. "demo_fee"=>$info["demo_fee"],
  944. "delivery_fee"=>$info["delivery_fee"],
  945. "open_fee"=>$info["open_fee"],
  946. "packing_fee"=>$info["pakge_fee"],
  947. "mark_fee"=>$info["mark_fee"],
  948. "nake_fee"=>$info["nake_fee"],
  949. "cert_fee"=>$info["cert_fee"],
  950. "cost_fee"=>$info["cost_fee"],
  951. "num"=>$bidinfo["num"],
  952. ];
  953. if($info['is_gold_price']==1){
  954. $price = GoldPrice($god, $budget/100);
  955. $info['sale_price'] =round($price,2);
  956. }
  957. $info['specinfo'] = json_decode($info['specinfo'],true);
  958. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  959. if($info['delivery_place']!=""){
  960. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  961. }
  962. $info['delivery_place_cn']=GetAddr(json_encode($place));
  963. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  964. if($info['origin_place']!=""){
  965. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  966. }
  967. $info['origin_place_cn']=GetAddr(json_encode($place));
  968. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  969. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  970. $info['bargain'] =$bargain;
  971. $info['good_img'] = explode(',',$info['good_img']);
  972. //添加商品创建人字段
  973. $good_info = Db::name('good_basic')
  974. ->field('id,createrid,creater')
  975. ->where('is_del',0)
  976. ->where('spuCode',$info['spuCode'])
  977. ->findOrEmpty();
  978. $info['good_createrid'] = $good_info['createrid']??0;
  979. $info['good_creater'] = $good_info['creater']??'';
  980. return app_show(0,"获取成功",$info);
  981. }
  982. //反馈商品编辑
  983. public function feededit(){
  984. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  985. if($bidNo==""){
  986. return error_show(1002,"参数bidNo不能为空");
  987. }
  988. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  989. if($bidinfo==false){
  990. return error_show(1003,"未找到信息数据");
  991. }
  992. if($bidinfo['status']>=5){
  993. return error_show(1004,"咨询单已确认无法修改");
  994. }
  995. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  996. if($zxinfo==false){
  997. return error_show(1003,"未找到信息数据");
  998. }
  999. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  1000. if($zx==false){
  1001. return error_show(1003,"未找咨询信息数据");
  1002. }
  1003. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  1004. if($pname==""){
  1005. return error_show(1002,"参数pname不能为空");
  1006. }
  1007. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  1008. // if($brandid==""){
  1009. // return error_show(1002,"参数brandid不能为空");
  1010. // }
  1011. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  1012. if($cat_id==""){
  1013. return error_show(1002,"参数cat_id不能为空");
  1014. }
  1015. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  1016. if($specin==""){
  1017. return error_show(1003,"参数specinfo不能为空");
  1018. }
  1019. $specinfo=[];
  1020. foreach ($specin as $v){
  1021. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  1022. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  1023. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  1024. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  1025. $specinfo[]=$v;
  1026. }
  1027. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  1028. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1029. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1030. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1031. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1032. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1033. :"";
  1034. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1035. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1036. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1037. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1038. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1039. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1040. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1041. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1042. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1043. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1044. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1045. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1046. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1047. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1048. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1049. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1050. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1051. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1052. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1053. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1054. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1055. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1056. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1057. if($delivery_place==''){
  1058. return error_show(1002,"参数delivery_place不能为空");
  1059. }
  1060. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1061. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1062. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1063. $cat_top_list = made($cat_id);
  1064. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1065. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1066. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1067. ->find();
  1068. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1069. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1070. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1071. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1072. $saleprice = $total_fee / (1 - $budget);
  1073. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1074. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1075. }else{
  1076. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1077. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1078. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1079. }
  1080. Db::startTrans();
  1081. try{
  1082. $data=[
  1083. "good_name"=>$pname,
  1084. "brand_id"=>$brandid,
  1085. "cat_id"=>$cat_id,
  1086. "specinfo"=>json_encode($specinfo),
  1087. // "material"=>$material,
  1088. "unit_id"=>$unit_id,
  1089. "cost_desc"=>$cost_desc,
  1090. "work_day"=>$work_day,
  1091. "delivery_day"=>$delivery_day,
  1092. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1093. "expire_day"=>$expire_day,
  1094. "origin_place"=>$origin_place,
  1095. "supplierNo"=>$supplierNo,
  1096. "pay_way"=>$pay_way,
  1097. "tax"=>$tax,
  1098. "send_way"=>$send_way,
  1099. "metal_id"=>$metal_id,
  1100. "is_gold_price"=>$is_gold_price,
  1101. "config"=>$config,
  1102. "other_config"=>$other_config,
  1103. "weight"=>$weight,
  1104. "good_weight"=>$noble_weight,
  1105. "is_diff"=>$is_diff,
  1106. "demo_fee"=>$demo_fee,
  1107. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1108. "delivery_fee"=>$delivery_fee,
  1109. "open_fee"=>$open_fee,
  1110. "pakge_fee"=>$pakge_fee,
  1111. "nake_fee"=>$nake_fee,
  1112. "mark_fee"=>$mark_fee,
  1113. "cert_fee"=>$cert_fee,
  1114. "cost_fee"=>$cost_fee,
  1115. "sale_cost_fee"=>$sale_cost_fee,
  1116. "origin_cost_fee"=>$sale_cost_fee,
  1117. "total_fee"=>$total_fee,
  1118. "sale_price"=>$saleprice,
  1119. "origin_price"=>$saleprice,
  1120. "supply_area"=>$supply_area,
  1121. "remark"=>$remark,
  1122. "status"=>0,
  1123. "updatetime"=>date("Y-m-d H:i:s"),
  1124. 'delivery_place' => $delivery_place
  1125. ];
  1126. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1127. if($insert){
  1128. if($zxinfo['bargain_status']==1){
  1129. $zxinfo['bargain_status']=0;
  1130. $infoip =Db::name("consult_info")->save($zxinfo);
  1131. if($infoip==false){
  1132. Db::rollback();
  1133. return error_show(1006,"咨询信息状态更新失败");
  1134. }
  1135. }
  1136. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1137. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1138. if($projectinfo==false){
  1139. Db::rollback();
  1140. return error_show(1006,"未找到项目信息");
  1141. }
  1142. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1143. if($feed!=false) {
  1144. $feed['good_name']=$pname;
  1145. $feed['good_type']=$projectinfo['good_type'];
  1146. $feed['cat_id']=$cat_id;
  1147. $feed['sale_price']=$saleprice;
  1148. $feed['origin_price']=$total_fee;
  1149. $feed['updatetime']=date("Y-m-d H:i:s");
  1150. $temp['updatetime']=date("Y-m-d H:i:s");
  1151. $nu=Db::name("project_feedback")->save($feed);
  1152. if ($nu == false) {
  1153. Db::rollback();
  1154. return error_show(1006 , "项目反馈失败");
  1155. } else {
  1156. $old_projectinfo_status=$projectinfo['status'];
  1157. $projectinfo['status']=2;
  1158. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1159. $up=Db::name("project_info")->save($projectinfo);
  1160. if ($up) {
  1161. //修改状态,添加待办,只记录动作
  1162. ActionLog::logAdd($this->post['token'] , [
  1163. "order_code"=>$projectinfo['pgNo'] ,//编码
  1164. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1165. "action_remark"=>'' ,//备注
  1166. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1167. ] , "PRI" , 2 , $projectinfo
  1168. );
  1169. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1170. if ($count == 0) {
  1171. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1172. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1173. if ($project_id) {
  1174. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1175. if ($proc == false) {
  1176. Db::rollback();
  1177. return error_show(1006 , "项目反馈失败");
  1178. } else {
  1179. //修改状态,添加待办
  1180. ActionLog::logAdd($this->post['token'] , [
  1181. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1182. "status"=>1 ,//这里的status是之前的值
  1183. "action_remark"=>'' ,//备注
  1184. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1185. ] , "PRO" , 2 , $this->post
  1186. );
  1187. ProcessOrder::AddProcess($this->post['token'] , [
  1188. "order_type"=>'PRO' ,
  1189. "order_code"=>$projectinfo['projectNo'] ,
  1190. "order_id"=>$project_id ,
  1191. "order_status"=>2 , "before_status"=>1
  1192. ]
  1193. );
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }
  1200. }
  1201. Db::commit();
  1202. return app_show(0,"编辑成功");
  1203. }else{
  1204. Db::rollback();
  1205. return error_show(1004,"编辑失败");
  1206. }
  1207. }catch (\Exception $e){
  1208. Db::rollback();
  1209. return error_show(1004,$e->getMessage());
  1210. }
  1211. }
  1212. //生成议价单
  1213. public function bargain_add(){
  1214. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1215. if($bidNo===""){
  1216. return error_show(1004,"参数bidNo不能为空");
  1217. }
  1218. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1219. if($info==false){
  1220. return error_show(1004,"未找到商品数据");
  1221. }
  1222. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1223. if($consult==false){
  1224. return error_show(1004,"未找到咨询数据");
  1225. }
  1226. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1227. if($bargain_price===""){
  1228. return error_show(1004,"参数bargain_price不能为空");
  1229. }
  1230. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1231. if($info['is_gold_price']==1){
  1232. if($cost_price==""){
  1233. return error_show(1004,"参数cost_price不能为空");
  1234. }
  1235. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1236. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1237. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1238. ->find();
  1239. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1240. }
  1241. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1242. // if($bargain_reason===""){
  1243. // return error_show(1004,"参数bargain_reason不能为空");
  1244. // }
  1245. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1246. if($infos==false){
  1247. return error_show(1004,"未找到商品数据");
  1248. }
  1249. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1250. return error_show(1004,"咨询单招标未结束或已确认商品");
  1251. }
  1252. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1253. if($token==''){
  1254. return error_show(105,"参数token不能为空");
  1255. }
  1256. $user =GetUserInfo($token);
  1257. if(empty($user)||$user['code']!=0){
  1258. return error_show(1002,"用户数据不存在");
  1259. }
  1260. //新增两个字段
  1261. //议价备注
  1262. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1263. //议价原因id
  1264. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1265. if ($result_info_id != '') {
  1266. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1267. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1268. }
  1269. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1270. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1271. $bargainNo =makeNo("BA");
  1272. Db::startTrans();//::todo 金价 毛利计算
  1273. try{
  1274. $data=[
  1275. "bidsNo"=>$bidNo,
  1276. "infoNo"=>$info['infoNo'],
  1277. "zxNo"=>$info['zxNo'],
  1278. "bargainNo"=>$bargainNo,
  1279. "bargain_type"=>1,
  1280. "bargain_reason"=>$bargain_reason,
  1281. "sale_price"=>$info['sale_price'],
  1282. "cost_before_price"=>$info['sale_cost_fee'],
  1283. "cost_after_price"=>$cost_price,
  1284. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1285. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1286. "after_price"=>$bargain_price,
  1287. "exam_info"=>"",
  1288. "status"=>0,
  1289. "is_del"=>0,
  1290. "creater"=>$creater,
  1291. "createrid"=>$createrid,
  1292. "addtime"=>date("Y-m-d H:i:s"),
  1293. "updatetime"=>date("Y-m-d H:i:s"),
  1294. 'bargain_remark'=>$bargain_remark,
  1295. 'result_info_id'=>$result_info_id,
  1296. ];
  1297. $int = Db::name("bargain_order")->insertGetId($data);
  1298. if($int){
  1299. //修改状态,添加待办
  1300. ActionLog::logAdd($this->post['token'], [
  1301. "order_code" => $bargainNo,//咨询单详情编号
  1302. "status" => 0,//这里的status是之前的值
  1303. "action_remark" => '',//备注
  1304. "action_type" => "status"//新建create,编辑edit,更改状态status
  1305. ], "YJD", $data['status'], $data);
  1306. ProcessOrder::AddProcess($this->post['token'], [
  1307. "order_type" => 'YJD',
  1308. "order_code" => $bargainNo,
  1309. "order_id" => $int,
  1310. "order_status" =>0,
  1311. "before_status"=>0,
  1312. 'holder_id'=>$data['createrid']
  1313. ]);
  1314. $odlstatus=$info['status'];
  1315. $info['status']=3;
  1316. $info['updatetime']=date("Y-m-d H:i:s");
  1317. $up =Db::name("consult_bids")->save($info);
  1318. if($up){
  1319. //修改状态,添加待办
  1320. ActionLog::logAdd($this->post['token'], [
  1321. "order_code" => $bidNo,//咨询单详情编号
  1322. "status" => $odlstatus,//这里的status是之前的值
  1323. "action_remark" => '',//备注
  1324. "action_type" => "status"//新建create,编辑edit,更改状态status
  1325. ], "FKD", $info['status'], $info);
  1326. $old_infos_status = $infos['status'];
  1327. $infos['status']=3;
  1328. $infos['updatetime']=date("Y-m-d H:i:s");
  1329. $ups =Db::name("consult_info")->save($infos);
  1330. if($ups){
  1331. //修改状态,添加待办
  1332. ActionLog::logAdd($this->post['token'], [
  1333. "order_code" => $infos['infoNo'],//咨询单详情编号
  1334. "status" => $old_infos_status,//这里的status是之前的值
  1335. "action_remark" => '',//备注
  1336. "action_type" => "status"//新建create,编辑edit,更改状态status
  1337. ], "ZXD", $infos['status'], $infos);
  1338. //维护台账信息
  1339. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1340. Db::commit();
  1341. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1342. }
  1343. }
  1344. }
  1345. Db::rollback();
  1346. return error_show(1004,"议价单新建失败");
  1347. }catch (\Exception $e){
  1348. Db::rollback();
  1349. return error_show(1004,$e->getMessage());
  1350. }
  1351. }
  1352. //选择商品
  1353. public function bids_check(){
  1354. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1355. if($bidNo===""){
  1356. return error_show(1004,"参数bidNo不能为空");
  1357. }
  1358. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1359. if($info==false){
  1360. return error_show(1004,"未找到商品数据");
  1361. }
  1362. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1363. if($infos==false){
  1364. return error_show(1004,"未找到商品数据");
  1365. }
  1366. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1367. return error_show(1004,"咨询单招标未结束或已确认商品");
  1368. }
  1369. Db::startTrans();
  1370. try {
  1371. $oldstattus=$info['status'];
  1372. $info['status']=6;
  1373. $info['updatetime']=date("Y-m-d H:i:s");
  1374. $bids = Db::name("consult_bids")->save($info);
  1375. if($bids){
  1376. //修改状态,添加待办
  1377. ActionLog::logAdd($this->post['token'], [
  1378. "order_code" =>$bidNo,//咨询单详情编号
  1379. "status" => $oldstattus,//这里的status是之前的值
  1380. "action_remark" => '',//备注
  1381. "action_type" => "status"//新建create,编辑edit,更改状态status
  1382. ], "FKD", $info['status'], $info);
  1383. $old_infos_status = $infos['status'];
  1384. $infos['status']=4;
  1385. $infos['updatetime']=date("Y-m-d H:i:s");
  1386. $se = Db::name("consult_info")->save($infos);
  1387. if($se){
  1388. //修改状态,添加待办
  1389. ActionLog::logAdd($this->post['token'], [
  1390. "order_code" => $infos['infoNo'],//咨询单详情编号
  1391. "status" => $old_infos_status,//这里的status是之前的值
  1392. "action_remark" => '',//备注
  1393. "action_type" => "status"//新建create,编辑edit,更改状态status
  1394. ], "ZXD", $infos['status'], $infos);
  1395. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1396. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1397. Db::commit();
  1398. return app_show(0,"商品确定成功");
  1399. }
  1400. }
  1401. Db::rollback();
  1402. return error_show(1004,"商品确认失败");
  1403. }catch (\Exception $e){
  1404. Db::rollback();
  1405. return error_show(1004,$e->getMessage());
  1406. }
  1407. }
  1408. //议价审核
  1409. /**
  1410. * status:
  1411. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1412. */
  1413. public function bargain_status(){
  1414. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1415. if($bargainNo===""){
  1416. return error_show(1004,"参数bargainNo不能为空");
  1417. }
  1418. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1419. if($info==false){
  1420. return error_show(1004,"未找到议价数据");
  1421. }
  1422. if($info['status']==12){
  1423. return error_show(1004,"议价单已取消");
  1424. }
  1425. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1426. if($bids==false){
  1427. return error_show(1004,"未找到商品数据");
  1428. }
  1429. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1430. if($coninfo==false){
  1431. return error_show(1004,"未找到咨询单数据");
  1432. }
  1433. if($bids['status']==6){
  1434. return error_show(1004,"咨询已选择商品");
  1435. }
  1436. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1437. if($status===''){
  1438. return error_show(1005,"参数status不能为空");
  1439. }
  1440. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1441. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1442. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1443. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1444. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1445. if($bids['is_gold_price']==1){
  1446. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1447. ->find();
  1448. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1449. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1450. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1451. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1452. $saleprice =$total_fe / (1 - $budget);
  1453. $rate_price = $total_fe / (1 - $rate);
  1454. $money_price =$total_fe / (1 - $money_rate);
  1455. $lower_price =$total_fe / (1 - $lower_rate);
  1456. }else{
  1457. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1458. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1459. if($bids['nake_fee']!=0){
  1460. $saleprice = ($total_fe)/ (1 - $budget);
  1461. $rate_price = ($total_fe)/ (1 - $rate);
  1462. $money_price =($total_fe)/ (1 - $money_rate);
  1463. $lower_price = ($total_fe) / (1 - $lower_rate);
  1464. }else{
  1465. $saleprice = $total_fe / (1 - $budget);
  1466. $rate_price =$total_fe/ (1 - $rate);
  1467. $money_price =$total_fe / (1 - $money_rate);
  1468. $lower_price = $total_fe/ (1 - $lower_rate);
  1469. }
  1470. }
  1471. $ra_status = $info['status'];
  1472. if($status==1){
  1473. if($info['status']==0){
  1474. if($info['after_price']<$rate_price){
  1475. $info['status']=2;
  1476. }else{
  1477. $info['status']=1;
  1478. }
  1479. }elseif($info['status']==2){
  1480. $info['status']=4;
  1481. }elseif($info['status']==4||$info['status']==5){
  1482. if($info['after_price']<$money_price){
  1483. $info['status']=7;
  1484. }else{
  1485. $info['status']=6;
  1486. }
  1487. }elseif($info['status']==7){
  1488. $info['lower_price'] =$lower_price;
  1489. if($info['after_price']<$lower_price){
  1490. $info['status']=10;
  1491. }else{
  1492. $info['status']=9;
  1493. }
  1494. }
  1495. }else{
  1496. if($info['status']==0){
  1497. $info['status']=3;
  1498. }elseif($info['status']==2){
  1499. $info['status']=4;
  1500. }elseif($info['status']==4||$info['status']==5){
  1501. $info['status']=8;
  1502. }elseif($info['status']==7){
  1503. $info['lower_price'] =$lower_price;
  1504. $info['status']=11;
  1505. }
  1506. }
  1507. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1508. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1509. if($token==''){
  1510. return error_show(105,"参数token不能为空");
  1511. }
  1512. $user =GetUserInfo($token);
  1513. if(empty($user)||$user['code']!=0){
  1514. return error_show(1002,"用户数据不存在");
  1515. }
  1516. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1517. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1518. Db::startTrans();
  1519. try{
  1520. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1521. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1522. "creater"=>$creater];
  1523. // $info['status'] =$status;
  1524. $info['remark'] =$remark;
  1525. $info['exam_info']=json_encode($examinfo) ;
  1526. $info['updatetime'] =date("Y-m-d H:i:s");
  1527. $up =Db::name("bargain_order")->save($info);
  1528. if($up){
  1529. //修改状态,添加待办
  1530. ActionLog::logAdd($this->post['token'], [
  1531. "order_code" => $bargainNo,//咨询单详情编号
  1532. "status" =>$ra_status,//这里的status是之前的值
  1533. "action_remark" => '',//备注
  1534. "action_type" => "status"//新建create,编辑edit,更改状态status
  1535. ], "YJD", $info['status'], $info);
  1536. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
  1537. ProcessOrder::AddProcess($token,$process);
  1538. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1539. $bidstatus=$bids['status'];
  1540. $bids['status']=5;
  1541. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1542. $bids['sale_price']=$info['after_price'];
  1543. if($bids['is_gold_price']==1){
  1544. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1545. // ->find();
  1546. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1547. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1548. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1549. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1550. }
  1551. }
  1552. $bids['updatetime']=date("Y-m-d H:i:s");
  1553. $up =Db::name("consult_bids")->save($bids);
  1554. if($up==false){
  1555. Db::rollback();
  1556. return error_show(1004,"数据更新失败");
  1557. }
  1558. ActionLog::logAdd($this->post['token'], [
  1559. "order_code" => $info["bidsNo"],//咨询单详情编号
  1560. "status" => $bidstatus,//这里的status是之前的值
  1561. "action_remark" => '',//备注
  1562. "action_type" => "status"//新建create,编辑edit,更改状态status
  1563. ], "FKD", $bids['status'], $bids);
  1564. }
  1565. Db::commit();
  1566. return app_show(0,"更新成功");
  1567. }
  1568. }catch (\Exception $e){
  1569. Db::rollback();
  1570. return error_show(1004,$e->getMessage());
  1571. }
  1572. }
  1573. public function bargain_info(){
  1574. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1575. if($bargainNo===""){
  1576. return error_show(1004,"参数bargainNo不能为空");
  1577. }
  1578. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1579. if($info==false){
  1580. return error_show(1004,"未找到议价数据");
  1581. }
  1582. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1583. if($bidinfos==false){
  1584. return error_show(1004,"未找到商品数据");
  1585. }
  1586. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1587. if($consultinfos==false){
  1588. return error_show(1004,"未找到咨询商品数据");
  1589. }
  1590. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1591. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1592. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1593. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1594. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1595. $info['before_rate'] =round($info['before_rate']*100,2);
  1596. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1597. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1598. $info['after_rate'] = round($info['after_rate']*100,2);
  1599. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1600. if($bidinfos['brand_id']!=0){
  1601. $info['brand_id'] = $bidinfos['brand_id'];
  1602. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1603. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1604. }else{
  1605. $info["brand_name"]="";
  1606. $info["brand_id"]="";
  1607. }
  1608. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1609. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1610. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1611. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1612. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1613. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1614. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1615. $info['budget'] =$budget;
  1616. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1617. if($info['after_rate']>=$catinfo['rate']){
  1618. //业务主管利率
  1619. $info['rate_status'] =1;
  1620. }
  1621. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1622. //财务主管利率
  1623. $info['rate_status'] =2;
  1624. }
  1625. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1626. //boss利率
  1627. $info['rate_status'] =3;
  1628. }
  1629. $god=[
  1630. "metal_id"=>$bidinfos['metal_id'],
  1631. "weight"=>$bidinfos["good_weight"],
  1632. "demo_fee"=>$bidinfos["demo_fee"],
  1633. "delivery_fee"=>$bidinfos["delivery_fee"],
  1634. "open_fee"=>$bidinfos["open_fee"],
  1635. "packing_fee"=>$bidinfos["pakge_fee"],
  1636. "mark_fee"=>$bidinfos["mark_fee"],
  1637. "nake_fee"=>$bidinfos["nake_fee"],
  1638. "cert_fee"=>$bidinfos["cert_fee"],
  1639. "cost_fee"=>$bidinfos["cost_fee"],
  1640. "num"=>$bidinfoe["num"],
  1641. ];
  1642. $info['gold_price']=0;
  1643. $info['noble_weight']=$bidinfos['good_weight'];
  1644. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1645. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1646. ->find();
  1647. $info['gold_price'] =$gold['price'];
  1648. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1649. }else{
  1650. if($bidinfos['nake_fee']!=0){
  1651. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1652. }else{
  1653. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1654. }
  1655. }
  1656. $info['cost_desc'] =$bidinfos['cost_desc'];
  1657. $info['work_day'] =$bidinfos['work_day'];
  1658. $info['delivery_day'] =$bidinfos['delivery_day'];
  1659. $info['expire_day'] =$bidinfos['expire_day'];
  1660. $info['origin_place'] =$bidinfos['origin_place'];
  1661. $info['origin_addr'] ="";
  1662. if($bidinfos['origin_place']!=''){
  1663. $code = explode(",",$bidinfos['origin_place']);
  1664. $temp=[];
  1665. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1666. $temp['city_code']=isset($code[1])?$code[1]:"";
  1667. $temp['area_code']=isset($code[2])?$code[2]:"";
  1668. $addr= GetAddr(json_encode($temp));
  1669. $info['origin_addr'] = $addr;
  1670. }
  1671. $info['supplierNo'] =$bidinfos['supplierNo'];
  1672. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1673. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1674. $info['pay_way'] =$bidinfos['pay_way'];
  1675. $info['tax'] =$bidinfos['tax'];
  1676. $info['send_way'] =$bidinfos['send_way'];
  1677. $info['metal_id'] =$bidinfos['metal_id'];
  1678. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1679. $info['config'] =$bidinfos['config'];
  1680. $info['other_config'] =$bidinfos['other_config'];
  1681. $info['weight'] =$bidinfos['weight'];
  1682. $info['good_weight'] =$bidinfos['good_weight'];
  1683. $info['is_diff'] =$bidinfos['is_diff'];
  1684. $info['demo_fee'] =$bidinfos['demo_fee'];
  1685. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1686. $info['open_fee'] =$bidinfos['open_fee'];
  1687. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1688. $info['nake_fee'] =$bidinfos['nake_fee'];
  1689. $info['mark_fee'] =$bidinfos['mark_fee'];
  1690. $info['cert_fee'] =$bidinfos['cert_fee'];
  1691. $info['cost_fee'] =$bidinfos['cost_fee'];
  1692. $info['total_fee'] =$bidinfos['total_fee'];
  1693. $info['supply_area'] =$bidinfos['supply_area'];
  1694. $info['remark'] =$bidinfos['remark'];
  1695. $info['is_addrs'] =$consultinfos['is_addrs'];
  1696. $info['is_custom'] =$consultinfos['is_custom'];
  1697. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1698. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1699. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1700. if($info['status']==7){
  1701. $info['lower_price'] =round($lower_price,2);
  1702. }
  1703. //获取议价原因
  1704. if ($info['result_info_id'] != 0) {
  1705. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1706. } else {
  1707. $info['result_info'] = '';
  1708. }
  1709. return app_show(0,"获取成功",$info);
  1710. }
  1711. public function bidlist(){
  1712. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1713. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1714. $where=[['is_del',"=",0]];
  1715. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1716. if ($zxNo !== "") {
  1717. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1718. }
  1719. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1720. if ($infoNo !== "") {
  1721. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1722. }
  1723. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1724. if ($bidNo !== "") {
  1725. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1726. }
  1727. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1728. if ($pgNo !== "") {
  1729. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1730. $where[] = ['infoNo','in',$bidinfo];
  1731. }
  1732. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1733. if ($bargain_status !== "") {
  1734. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1735. $where[] = ['infoNo','in',$bidinfo];
  1736. }
  1737. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1738. if ($projectNo !== "") {
  1739. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1740. ("zxNo");
  1741. $where[] = ['zxNo','in',$zxlist];
  1742. }
  1743. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1744. if($is_own==1){
  1745. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1746. if($token==""){
  1747. return error_show(101,'token不能为空');
  1748. }
  1749. $apply_id =GetUserInfo($token);
  1750. if(empty($apply_id)||$apply_id['code']!=0){
  1751. return error_show(1002,"申请人数据不存在");
  1752. }
  1753. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1754. $where[]=['createrid',"=",$rm];
  1755. }
  1756. $count = Db::name('consult_bids')->where($where)->count();
  1757. $total = ceil($count / $size);
  1758. $page = $page >= $total ? $total : $page;
  1759. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1760. $data=[];
  1761. foreach ($list as $value){
  1762. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1763. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1764. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1765. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1766. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1767. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1768. if($value['brand_id']!=0){
  1769. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1770. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1771. }else{
  1772. $value["brand_name"]="";
  1773. $value["brand_id"]="";
  1774. }
  1775. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1776. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1777. $god=[
  1778. "metal_id"=>$value['metal_id'],
  1779. "weight"=>$value["good_weight"],
  1780. "demo_fee"=>$value["demo_fee"],
  1781. "delivery_fee"=>$value["delivery_fee"],
  1782. "open_fee"=>$value["open_fee"],
  1783. "packing_fee"=>$value["pakge_fee"],
  1784. "mark_fee"=>$value["mark_fee"],
  1785. "nake_fee"=>$value["nake_fee"],
  1786. "cert_fee"=>$value["cert_fee"],
  1787. // "cost_fee"=>$value["cost_fee"],
  1788. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1789. //暂时注掉,搞不清楚原因@吴广广
  1790. "num"=>$bidinfo["num"],
  1791. ];
  1792. $top_cat = made($value['cat_id']);
  1793. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1794. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1795. $price = GoldPrice($god, $budget/100);
  1796. $value['sale_price'] = round($price,2);
  1797. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1798. $value["origin_price"];
  1799. }
  1800. $value['cost_fee'] =$value['origin_cost_fee'];
  1801. $value['specinfo'] = json_decode($value['specinfo'],true);
  1802. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1803. $value['bargain_status']=$bidinfo['bargain_status'];
  1804. //reject驳回原因,status==5表示驳回
  1805. $value['reject']=[];
  1806. if ($value['status'] >=5) {
  1807. $value['reject'] = Db::name('bargain_order')
  1808. ->field('id,remark,status')
  1809. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1810. ->whereIn('status', [3,8,11])->order("id desc")
  1811. ->find();
  1812. }
  1813. //产地
  1814. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1815. if($value['delivery_place']!=""){
  1816. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1817. }
  1818. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1819. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1820. if($value['origin_place']!=""){
  1821. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1822. }
  1823. $value['origin_addr']=GetAddr(json_encode($place));
  1824. // if($value['origin_place']!=''){
  1825. // $code = explode(",",$value['origin_place']);
  1826. // $temp=[];
  1827. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1828. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1829. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1830. // $addr= GetAddr(json_encode($temp));
  1831. // $value['origin_addr'] = $addr;
  1832. // }
  1833. $good_info = Db::name('good_basic')
  1834. ->field('id,createrid,creater')
  1835. ->where('is_del',0)
  1836. ->where('spuCode',$value['spuCode'])
  1837. ->findOrEmpty();
  1838. $value['good_createrid']=$good_info['createrid']??$value['createrid'];
  1839. $value['good_creater']=$good_info['creater']??$value['creater'];
  1840. $data[] = $value;
  1841. }
  1842. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1843. }
  1844. public function feedlist(){
  1845. $where=[['is_del',"=",0]];
  1846. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1847. if ($zxNo !== "") {
  1848. $where[] = ['zxNo','=',$zxNo];
  1849. }
  1850. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1851. if ($infoNo !== "") {
  1852. $where[] = ['infoNo','=',$infoNo];
  1853. }
  1854. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1855. if ($bidNo !== "") {
  1856. $where[] = ['bidNo','=',$bidNo];
  1857. }
  1858. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1859. if ($projectNo !== "") {
  1860. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1861. ("zxNo");
  1862. $where[] = ['zxNo','in',$zxlist];
  1863. }
  1864. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1865. if($token==''){
  1866. return error_show(102,"参数token不能为空");
  1867. }
  1868. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1869. if($is_own==1){
  1870. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1871. if($token==""){
  1872. return error_show(101,'token不能为空');
  1873. }
  1874. $apply_id =GetUserInfo($token);
  1875. if(empty($apply_id)||$apply_id['code']!=0){
  1876. return error_show(1002,"申请人数据不存在");
  1877. }
  1878. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1879. $where[]=['createrid',"=",$rm];
  1880. }
  1881. $list =Db::name('consult_bids')->where($where)->select();
  1882. $data=[];
  1883. foreach ($list as $value){
  1884. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1885. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1886. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1887. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1888. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1889. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1890. if($value['brand_id']!=0){
  1891. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1892. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1893. }else{
  1894. $value["brand_name"]="";
  1895. $value["brand_id"]="";
  1896. }
  1897. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1898. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1899. $god=[
  1900. "metal_id"=>$value['metal_id'],
  1901. "weight"=>$value["good_weight"],
  1902. "demo_fee"=>$value["demo_fee"],
  1903. "delivery_fee"=>$value["delivery_fee"],
  1904. "open_fee"=>$value["open_fee"],
  1905. "packing_fee"=>$value["pakge_fee"],
  1906. "mark_fee"=>$value["mark_fee"],
  1907. "nake_fee"=>$value["nake_fee"],
  1908. "cert_fee"=>$value["cert_fee"],
  1909. "cost_fee"=>$value["cost_fee"],
  1910. "num"=>$bidinfo["num"],
  1911. ];
  1912. if ($value['is_gold_price'] == 1 ) {
  1913. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1914. ->find();
  1915. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1916. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1917. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1918. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1919. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1920. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1921. }else{
  1922. if($value["nake_fee"]){
  1923. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1924. }else{
  1925. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1926. (1 - $budget);
  1927. }
  1928. }
  1929. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1930. $value['specinfo'] = json_decode($value['specinfo'],true);
  1931. $value['bargain_status']=$bidinfo['bargain_status'];
  1932. $data[]=$value;
  1933. }
  1934. return app_show(0,"获取成功",$data);
  1935. }
  1936. public function bragain_list(){
  1937. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1938. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1939. $where=[['bo.is_del',"=",0]];
  1940. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1941. if($bidsNo!=""){
  1942. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1943. }
  1944. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1945. if ($zxNo !== "") {
  1946. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1947. }
  1948. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1949. if ($bargainNo !== "") {
  1950. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1951. }
  1952. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1953. if ($status!== "") {
  1954. $where[] = ['bo.status','=',$status];
  1955. }
  1956. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1957. if ($infoNo !== "") {
  1958. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1959. }
  1960. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1961. if ($projectNo !== "") {
  1962. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column("zxNo");
  1963. $where[] = ['bo.zxNo','in',$zxlist];
  1964. }
  1965. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1966. if ($pgNo !== "") {
  1967. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1968. $where[] = ['bo.infoNo','in',$bidinfo];
  1969. }
  1970. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1971. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1972. if($start!=""){
  1973. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1974. }
  1975. if($end!=""){
  1976. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1977. }
  1978. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1979. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1980. // $role=$this->checkRole();
  1981. // if(!empty($role['write'])){
  1982. // $where[]=["bo.createrid","in",$role['write']];
  1983. // }
  1984. // $role = $this->checkDataShare();
  1985. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
  1986. $role = $this->checkDataShare();
  1987. $hand = resign_hand_user($this->uid,0);
  1988. if (!empty($role[DataGroupModel::$type_全部])) {
  1989. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  1990. $where[] = ['bo.createrid', 'in',$arr];
  1991. }
  1992. $count=Db::name("bargain_order")
  1993. ->alias('bo')
  1994. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1995. ->where($where)
  1996. ->count();
  1997. $total = ceil($count / $size);
  1998. $page = $page >= $total ? $total : $page;
  1999. $list = Db::name('bargain_order')
  2000. ->alias('bo')
  2001. ->where($where)
  2002. ->page($page, $size)
  2003. ->order('bo.addtime', 'desc')
  2004. ->select()
  2005. ->toArray();
  2006. $all_createrid = array_column($list,'createrid');
  2007. $item = get_company_name_by_uid($all_createrid);
  2008. $data=[];
  2009. foreach ($list as $value){
  2010. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  2011. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  2012. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  2013. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  2014. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  2015. if($bidinfos['brand_id']!=0){
  2016. $value['brand_id'] = $bidinfos['brand_id'];
  2017. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  2018. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2019. }else{
  2020. $value["brand_name"]="";
  2021. $value["brand_id"]="";
  2022. }
  2023. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  2024. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  2025. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  2026. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2027. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  2028. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  2029. $value['budget'] =$budget;
  2030. $god=[
  2031. "metal_id"=>$bidinfos['metal_id'],
  2032. "weight"=>$bidinfos["good_weight"],
  2033. "demo_fee"=>$bidinfos["demo_fee"],
  2034. "delivery_fee"=>$bidinfos["delivery_fee"],
  2035. "open_fee"=>$bidinfos["open_fee"],
  2036. "packing_fee"=>$bidinfos["pakge_fee"],
  2037. "mark_fee"=>$bidinfos["mark_fee"],
  2038. "nake_fee"=>$bidinfos["nake_fee"],
  2039. "cert_fee"=>$bidinfos["cert_fee"],
  2040. "cost_fee"=>$bidinfos["cost_fee"],
  2041. "num"=>$bidinfoe["num"],
  2042. ];
  2043. // if($bidinfos['is_gold_price']==1){
  2044. // $price = GoldPrice($god, $budget/100);
  2045. // }else{
  2046. // $price = GoodPrice($god, $budget/100);
  2047. // }
  2048. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  2049. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2050. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2051. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2052. $value['company_name'] = $item[$value['createrid']]??'';
  2053. //是否具有编辑权限
  2054. $value['is_allow_update'] = 0;
  2055. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2056. $data[]=$value;
  2057. }
  2058. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2059. }
  2060. public function crontablist(){
  2061. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2062. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2063. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2064. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2065. if ($zxNo !== "") {
  2066. $where[] = ['a.zxNo','=',$zxNo];
  2067. }
  2068. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2069. if ($salesman !== "") {
  2070. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2071. $where[]= ["b.salesman",'like',"%$salesman%"];
  2072. }
  2073. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2074. if ($cpName !== "") {
  2075. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2076. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2077. }
  2078. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2079. if ($khNo !== "") {
  2080. // $where['khNo'] = $khNo;
  2081. $where[]= ["b.khNo",'like',"%$khNo%"];
  2082. }
  2083. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2084. if ($start !="") {
  2085. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2086. $where[]= ["a.addtime",'>=',$start];
  2087. }
  2088. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2089. if($end !=""){
  2090. $where[]= ["a.addtime",'<=',$end];
  2091. }
  2092. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2093. if ($status !== "") {
  2094. $where[]= ["a.status",'=',$status];
  2095. }
  2096. //查看非本公司的竞价单
  2097. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  2098. if($relaComNo!="") $where[]=['b.companyNo','<>', $relaComNo];
  2099. // $role=$this->checkRole();
  2100. // if(!empty($role['platform']) ){
  2101. // $where[]=["b.platform_code","in",$role['platform']];
  2102. // }
  2103. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2104. ->count();
  2105. $total = ceil($count / $size);
  2106. $page = $page >= $total ? $total : $page;
  2107. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2108. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2109. $data=[];
  2110. foreach ($list as $value){
  2111. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2112. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2113. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2114. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2115. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2116. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2117. $value['khname']="";
  2118. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2119. true):[];
  2120. if($value['khNo']!==""){
  2121. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2122. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2123. }
  2124. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2125. ->find();
  2126. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2127. $value['is_feed'] =$consult==false?0:1;
  2128. $value['is_all_feed'] =$consults==false?0:1;
  2129. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2130. $data[]=$value;
  2131. }
  2132. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2133. }
  2134. //复制上面的bidlist方法,只更改排序方式
  2135. public function bidlistCopy()
  2136. {
  2137. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2138. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2139. $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
  2140. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2141. if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2142. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2143. if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2144. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2145. if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2146. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2147. if ($pgNo !== "") {
  2148. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2149. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2150. }
  2151. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2152. if ($bargain_status !== "") {
  2153. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2154. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2155. }
  2156. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2157. if ($projectNo !== "") {
  2158. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  2159. $where[] = ['cb.zxNo', 'in', $zxlist];
  2160. }
  2161. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2162. if ($is_own == 1) {
  2163. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2164. if ($token == "") return error_show(101, 'token不能为空');
  2165. $apply_id = GetUserInfo($token);
  2166. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2167. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2168. $where[] = ['cb.createrid', "=", $rm];
  2169. }
  2170. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2171. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2172. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2173. if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
  2174. $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
  2175. if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
  2176. $count = Db::name('consult_bids')
  2177. ->alias('cb')
  2178. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2179. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2180. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2181. ->where($where)
  2182. ->count();
  2183. $total = ceil($count / $size);
  2184. $page = $page >= $total ? $total : $page;
  2185. $list = Db::name('consult_bids')
  2186. ->alias('cb')
  2187. ->field('cb.*,s.name supplierName')
  2188. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2189. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2190. ->where($where)
  2191. ->page($page, $size)
  2192. ->order('cb.addtime', 'desc')
  2193. ->select()
  2194. ->toArray();
  2195. $data = [];
  2196. foreach ($list as $value) {
  2197. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2198. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2199. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2200. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2201. // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2202. // $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2203. if ($value['brand_id'] != 0) {
  2204. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2205. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2206. } else {
  2207. $value["brand_name"] = "";
  2208. $value["brand_id"] = "";
  2209. }
  2210. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2211. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2212. $god = [
  2213. "metal_id" => $value['metal_id'],
  2214. "weight" => $value["good_weight"],
  2215. "demo_fee" => $value["demo_fee"],
  2216. "delivery_fee" => $value["delivery_fee"],
  2217. "open_fee" => $value["open_fee"],
  2218. "packing_fee" => $value["pakge_fee"],
  2219. "mark_fee" => $value["mark_fee"],
  2220. "nake_fee" => $value["nake_fee"],
  2221. "cert_fee" => $value["cert_fee"],
  2222. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2223. "num" => $bidinfo["num"],
  2224. ];
  2225. if ($value['is_gold_price'] == 1) {
  2226. $price = GoldPrice($god, $budget / 100);
  2227. $value['sale_price'] = round($price, 2);
  2228. }
  2229. $value['cost_fee'] = $value['origin_cost_fee'];
  2230. $value['specinfo'] = json_decode($value['specinfo'], true);
  2231. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2232. $value['bargain_status'] = $bidinfo['bargain_status'];
  2233. //reject驳回原因,status==5表示驳回
  2234. $value['reject'] = [];
  2235. if ($value['status'] >= 5) {
  2236. $value['reject'] = Db::name('bargain_order')
  2237. ->field('id,remark,status')
  2238. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2239. ->whereIn('status', [3, 8, 11])->order("id desc")
  2240. ->find();
  2241. }
  2242. //产地
  2243. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2244. if ($value['delivery_place'] != "") {
  2245. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2246. }
  2247. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2248. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2249. if ($value['origin_place'] != "") {
  2250. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2251. }
  2252. $value['origin_addr'] = GetAddr(json_encode($place));
  2253. // if($value['origin_place']!=''){
  2254. // $code = explode(",",$value['origin_place']);
  2255. // $temp=[];
  2256. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2257. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2258. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2259. // $addr= GetAddr(json_encode($temp));
  2260. // $value['origin_addr'] = $addr;
  2261. // }
  2262. $value['company_name'] = $item[$value['createrid']]??'';
  2263. $data[] = $value;
  2264. }
  2265. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2266. }
  2267. }